﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Team4.users
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BLL.Security.PageSecurityAdminOnly(this);
        }

        protected void addUserButton_OnClick(object sender, EventArgs e)
        {
            string userName = userNameTextBox.Text;
            string password = passwordTextBox.Text;
            string email = emailTextBox.Text;
            bool admin = adminCheckBox.Checked;

            // If nothing is entered do not create a room.
            if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(email)) return;

            // Create a new room.
            BLL.User.CreateUser(userName, email, admin, password);

            // Refresh grid view with new room.
            UserObjectDataSource.DataBind();
            UserGridView.DataBind();

            // Clear text boxes.
            userNameTextBox.Text = string.Empty;
            passwordTextBox.Text = string.Empty;
            emailTextBox.Text = string.Empty;
            adminCheckBox.Checked = false;
        }
    }
}